********************************************************************************
** 	TITLE:		us2000_anes_contact_networks                                  ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       anes2000TS                                                    **
**  DATE:	    October 2022 						                          **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "us2000_anes_contact_networks", replace

* Open the dataset

use "anes2000TS.dta", clear


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen sdate = "2000" + V000008

gen surveydate = date(sdate,"YMD")

format %tdMon_DD,_CCYY surveydate

gen edate = 20001107

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) - 1 // Substract 1 to correct for election date

* Gender

gen male = V001029

recode male (2=0)

* Age

gen age = V000908

recode age (0=.)

replace age = . if age < 18

* Education

gen education = V000913

recode education (9=.)

* Interest for election

gen interest = V000301

recode interest (9=.)

replace interest = 6 - interest

replace interest = 2 if interest == 3
replace interest = 3 if interest == 5

* Caring about outcome (president)

gen care_whole = V000302

recode care_whole (3=0)
recode care_whole (8=.)

* Caring about outcome (House)

gen care_house = V000342

recode care_house (8=.)

replace care_house = 5 - care_house

* Closeness of election (president)

gen closeness_whole = max(V000486,V000487)

recode closeness_whole (0=.)
recode closeness_whole (8=.)

recode closeness_whole (1=0)
recode closeness_whole (5=1)

* Party identification scale (national)

gen pidscale = V000523

recode pidscale (7=.) // Other minor party (only one respondent) recoded as missing data
recode pidscale (8=3) // Apolitical recoded as Independent
recode pidscale (9=.) // NA recoded as missing data

replace pidscale = pidscale + 1

gen pidscale_whole = pidscale

label define pidscale 1 "Strong loser PID" 2 "Weak loser PID" 3 "Leaner loser PID" 4 "No PID" 5 "Leaner winner PID" 6 "Weak winner PID" 7 "Strong winner PID"
label values pidscale_whole pidscale

* News attentiveness

gen news = V001648

recode news (0=.)
recode news (8=.)

replace news = 6 - news

* Tony Blair - Correct answer (British Prime Minister) = 1, Incorrect answer = 0

gen blair = V001453

recode blair (0=.)
recode blair (9=.)
recode blair (5=0)
recode blair (8=0)

* Trent Lott - Correct answer (Mississippi senator) = 1, Incorrect answer = 0

gen lott = V001447

recode lott (0=.)
recode lott (9=.)
recode lott (5=0)
recode lott (8=0)

* William Rehnquist - Correct answer (Supreme Court Justice) = 1, Incorrect answer = 0

gen rehnquist = V001450

recode rehnquist (0=.)
recode rehnquist (9=.)
recode rehnquist (5=0)
recode rehnquist (8=0)

* Janet Reno - Correct answer (Attorney General) = 1, Incorrect answer = 0

gen reno = V001456

recode reno (0=.)
recode reno (9=.)
recode reno (5=0)
recode reno (8=0)

* Party with the most members in the U.S. House of Representatives before election - Correct answer (Republican) = 1, Incorrect answer = 0

gen house = V001356

recode house (0=.)
recode house (1=0)
recode house (5=1)
recode house (8=0)

* Party with the most members in the U.S. Senate before election - Correct answer (Republican) = 1, Incorrect answer = 0

gen senate = V001357

recode senate (0=.)
recode senate (1=0)
recode senate (5=1)
recode senate (8=0)

* U.S. state George W. Bush lives in now - Correct answer (Texas) = 1, Incorrect answer = 0

gen bushstate = V001458

recode bushstate (0=.)
recode bushstate (9=.)

replace bushstate = 0 if bushstate!=3 & bushstate!=.
replace bushstate = 1 if bushstate == 3

* George W. Bush religion - Correct answer (Methodist) = 1, Incorrect answer = 0

gen bushreligion = V001460

recode bushreligion (9=.)

replace bushreligion = 0 if bushreligion!=2 & bushreligion!=.
replace bushreligion = 1 if bushreligion == 2

* U.S. state Al Gore is from originally - Correct answer (Tennessee) = 1, Incorrect answer = 0

gen gorestate = V001462

recode gorestate (0=.)
recode gorestate (9=.)

replace gorestate = 0 if gorestate!=2 & gorestate!=.
replace gorestate = 1 if gorestate == 2

* Al Gore religion - Correct answer (Baptist) = 1, Incorrect answer = 0

gen gorereligion = V001464

recode gorereligion (9=.)

replace gorereligion = 0 if gorereligion!=1 & gorereligion!=.
replace gorereligion = 1 if gorereligion == 1

* U.S. state Dick Cheney lives in now - Correct answer (Wyoming) = 1, Incorrect answer = 0

gen cheneystate = V001466

recode cheneystate (0=.)
recode cheneystate (9=.)

replace cheneystate = 0 if cheneystate!=4 & cheneystate!=.
replace cheneystate = 1 if cheneystate == 4

* Dick Cheney religion - Correct answer (Methodist) = 1, Incorrect answer = 0

gen cheneyreligion = V001468

recode cheneyreligion (9=.)

replace cheneyreligion = 0 if cheneyreligion!=2 & cheneyreligion!=.
replace cheneyreligion = 1 if cheneyreligion == 2

* U.S. state Joseph Lieberman lives in now - Correct answer (Connecticut) = 1, Incorrect answer = 0

gen liebermanstate = V001470

recode liebermanstate (0=.)
recode liebermanstate (9=.)

replace liebermanstate = 0 if liebermanstate!=1 & liebermanstate!=.
replace liebermanstate = 1 if liebermanstate == 1

* Joseph Lieberman religion - Correct answer (Jewish) = 1, Incorrect answer = 0

gen liebermanreligion = V001472

recode liebermanreligion (9=.)

replace liebermanreligion = 0 if liebermanreligion!=3 & liebermanreligion!=.
replace liebermanreligion = 1 if liebermanreligion == 3

* Political knowledge index

gen knowledge = blair + lott + rehnquist + reno + house + senate + bushstate + bushreligion + gorestate + gorereligion + cheneystate + cheneyreligion + liebermanstate + liebermanreligion

* Political discussion

gen discussion = V001205

recode discussion (0=.)
recode discussion (96=0)
recode discussion (98=.)

replace discussion = 0 if V001204 == 5

gen discussion_3pts = 0 if discussion < 2 & discussion!=.
replace discussion_3pts = 1 if discussion >= 2 & discussion < 4 & discussion!=.
replace discussion_3pts = 2 if discussion >= 4 & discussion!=.


*********************************************
** NATIONAL-LEVEL EXPECTATIONS (PRESIDENT) **
*********************************************

* Forecasts (1 = Democrat, 2 = Republican, 3 = Pat Buchanan, 4 = Ralph Nader, 7 = other)

gen forecast_whole = V000485

recode forecast_whole (9=.)

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=2 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 2


*****************************************
** NATIONAL-LEVEL EXPECTATIONS (HOUSE) **
*****************************************

* Forecasts (1 = Republican, 5 = Democrat, 8 = don't know)

gen forecast_house = V000797

recode forecast_house (0=.)
recode forecast_house (9=.)

* Identify correct forecasts

gen correct_house_d = 0 if forecast_house!=1 & forecast_house!=.
replace correct_house_d = 1 if forecast_house == 1


******************************************
** NATIONAL-LEVEL EXPECTATIONS (SENATE) **
******************************************

* Forecasts (1 = Republican, 5 = Democrat, 8 = don't know)

gen forecast_senate = V000798

recode forecast_senate (0=.)
recode forecast_senate (9=.)

* Identify correct forecasts

gen correct_senate_d = 0 if forecast_senate!=1 & forecast_senate!=.
replace correct_senate_d = 1 if forecast_senate == 1


**********
** SAVE **
**********

save "us2000_anes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (president)

logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (House)

logistic correct_house_d discussion pidscale_whole interest news knowledge i.care_house age i.male education time
estimates table, star(.05 .01 .001)

tab correct_house_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (Senate)

logistic correct_senate_d discussion pidscale_whole interest news knowledge age i.male education time
estimates table, star(.05 .01 .001)

tab correct_senate_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_house_d "House winner (DV)"
label variable correct_senate_d "Senate winner (DV)"
label variable discussion "Discussion"
label variable pidscale_whole "National PID"
label variable interest "Interest"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable care_whole "Caring about outcome"
label variable care_house "Caring about outcome"
label variable closeness_whole "Perceived closeness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

quietly logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time

estpost tabstat correct_whole_d discussion pidscale_whole interest news knowledge care_whole closeness_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2000_anes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2000 American presidential election (ANES), national level") replace

eststo clear

quietly logistic correct_house_d discussion pidscale_whole interest news knowledge care_house age i.male education time

estpost tabstat correct_house_d discussion pidscale_whole interest news knowledge care_house age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2000_anes_summary_house.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2000 American House elections (ANES), national level") replace

eststo clear

quietly logistic correct_senate_d discussion pidscale_whole interest news knowledge age i.male education time

estpost tabstat correct_senate_d discussion pidscale_whole interest news knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2000_anes_summary_senate.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2000 American Senate elections (ANES), national level") replace

eststo clear

log close